'use strict';
module.exports = async (obj) => {
	let user_order_success = true;
	let { data = {} } = obj;
	let {
		order_no,
		out_trade_no,
		total_fee
	} = data; // uni-pay-orders 表内的数据均可获取到

	var db = uniCloud.database();
	var result = await db.collection('recharge_log').where({order_no:order_no}).get({getOne:true});
	//判断支付金额与实际金额是否一致
	var order = result.data[0];
	var money = order.money;
	var give_money = order.give_money;
	
	if(money - give_money!=total_fee){
		return false;
	}else{
		//更新支付状态
		var updateResult = await db.collection('recharge_log').where({order_no:order_no}).update({is_pay:1});
		if(updateResult.updated==1){
			//把金额增加到用户表
			var user = uniCloud.importObject('users',{customUI:true});
			user.setUsersMoney(order_no,money);
			return true;
		}
	}
	
};
